//
// Created by hentai on 2025/8/28.
//

#include "ResponsiveSplitter.h"

ResponsiveSplitter::ResponsiveSplitter(Qt::Orientation orientation, QWidget *parent) : QSplitter(orientation, parent) {
    // 创建左右两个widget
    leftWidget = new QWidget(this);
    rightWidget = new QWidget(this);

    // 设置widget的背景色以便区分
    leftWidget->setStyleSheet("background-color: #FFCCCC;");
    rightWidget->setStyleSheet("background-color: #CCFFCC;");

    // 添加widget到splitter
    addWidget(leftWidget);
    addWidget(rightWidget);

    // 设置初始比例
    updateSplitRatio();
}

void ResponsiveSplitter::resizeEvent(QResizeEvent *event) {
    QSplitter::resizeEvent(event);
    updateSplitRatio();
}

void ResponsiveSplitter::updateSplitRatio() {
    if (width() > 800) {
        // 宽度超过800时使用3:7比例
        setSizes({width() * 3 / 10, width() * 7 / 10});
    } else {
        // 宽度小于等于800时使用1:9比例
        setSizes({width() * 1 / 10, width() * 9 / 10});
    }
}
